home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / inc / avoffset.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-09  |  3.3 KB  |  109 lines

  1. /* @(#)avoffset.c    1.14 00/02/09 Copyright 1987 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)avoffset.c    1.14 00/02/09 Copyright 1987 J. Schilling";
  5. #endif
  6. /*
  7.  * This program is a tool to generate the file "avoffset.h".
  8.  * It is used by functions that trace the stack to get to the top of the stack.
  9.  *
  10.  * It generates two defines:
  11.  *    AV_OFFSET    - offset of argv relative to the main() frame pointer
  12.  *    FP_INDIR    - number of stack frames above main()
  13.  *              before encountering a NULL pointer.
  14.  *
  15.  *    Copyright (c) 1987 J. Schilling
  16.  */
  17. /*
  18.  * This program is free software; you can redistribute it and/or modify
  19.  * it under the terms of the GNU General Public License as published by
  20.  * the Free Software Foundation; either version 2, or (at your option)
  21.  * any later version.
  22.  *
  23.  * This program is distributed in the hope that it will be useful,
  24.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26.  * GNU General Public License for more details.
  27.  *
  28.  * You should have received a copy of the GNU General Public License
  29.  * along with this program; see the file COPYING.  If not, write to
  30.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  */
  32.  
  33. #include <mconfig.h>
  34. #include <stdio.h>
  35. #include <standard.h>
  36. #include <stdxlib.h>
  37. #include <signal.h>
  38.  
  39. #ifdef    NO_SCANSTACK
  40. #    ifdef    HAVE_SCANSTACK
  41. #    undef    HAVE_SCANSTACK
  42. #    endif
  43. #endif
  44.  
  45. #ifdef    HAVE_SCANSTACK
  46. #    include <stkframe.h>
  47. #endif
  48.  
  49. LOCAL    RETSIGTYPE handler __PR((int signo));
  50. EXPORT    int    main    __PR((int ac, char** av));
  51.  
  52. LOCAL    RETSIGTYPE
  53. handler(signo)
  54.     int    signo;
  55. {
  56.     fprintf(stderr, "Warning: Cannot scan stack on this environment.\n");
  57.     exit(0);
  58. }
  59.  
  60.  
  61. int main(ac, av)
  62.     int    ac;
  63.     char    **av;
  64. {
  65. #ifdef    HAVE_SCANSTACK
  66.     register struct frame *fp = (struct frame *)getfp();
  67.     register int    i = 0;
  68. #endif
  69.  
  70.     signal(SIGBUS, handler);
  71.     signal(SIGSEGV, handler);
  72.  
  73.     printf("/*\n");
  74.     printf(" * This file has been generated automatically\n");
  75.     printf(" * by %s\n", sccsid);
  76.     printf(" * do not edit by hand.\n");
  77.     printf(" *\n");
  78.     printf(" * This file includes definitions for AV_OFFSET and FP_INDIR.\n");
  79.     printf(" * FP_INDIR is the number of fp chain elements above 'main'.\n");
  80.     printf(" * AV_OFFSET is the offset of &av[0] relative to the frame pointer in 'main'.\n");
  81.     printf(" *\n");
  82.     printf(" * If getav0() does not work on a specific architecture\n");
  83.     printf(" * the program which generated this include file may dump core.\n");
  84.     printf(" * In this case, the generated include file does not include\n");
  85.     printf(" * definitions for AV_OFFSET and FP_INDIR but ends after this comment.\n");
  86.     printf(" * If AV_OFFSET or FP_INDIR are missing in this file, all programs\n");
  87.     printf(" * which use the definitions are automatically disabled.\n");
  88.     printf(" */\n");
  89.     fflush(stdout);
  90.  
  91. #ifdef    HAVE_SCANSTACK
  92.     while (fp->fr_savfp) {
  93.         fp = (struct frame *)fp->fr_savfp;
  94.         if (fp->fr_savpc == 0)
  95.             break;
  96.         i++;
  97.     }
  98.     /*
  99.      * Do not add any printf()'s before this line to allow avoffset
  100.      * to abort without printing more than the comment above.
  101.      */
  102.     fp = (struct frame *)getfp();
  103.     printf("#define    AV_OFFSET    %d\n", (int)(av-(char **)fp));
  104.     printf("#define    FP_INDIR    %d\n", i);
  105. #endif
  106.     exit(0);
  107.     return (0);    /* keep lint happy */
  108. }
  109.